﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;

namespace Shuba.Web.approval_assigment
{
    public partial class topup_assignment : basePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string acl = GetUserAccess("ASSIGN_TOPUP");

                if (!IsUserAdd(acl) && !IsUserEdit(acl))
                {
                    string msg = this.GetGlobalResourceObject("Messages", "NoPrivilege").ToString();
                    AlertAndRedirect(msg, ResolveUrl(ConfigurationManager.AppSettings["default_url"]));
                }

                LabelTitle.Text = GetPageTitle("ASSIGN_TOPUP");

                BindUserSO();
                Shuba.Business.TopUp bl = new Shuba.Business.TopUp();
                Shuba.Model.TopUpInfo bi;

                bi = bl.Get(Request.QueryString["cif"], Request.QueryString["loan"]);
                txtCIFNumber.Text = bi.CIF_NUMBER;
                txtLoanNumber.Text = bi.LOAN_NUMBER;
                txtDebtorName.Text = bi.DEBITOR_NAME;
                txtKodeProduk.Text = bi.PRODUCT_CODE;
                txtCurrentOS.Text = bi.CURRENT_OS.ToString("n0");
                txtCurrentInstallment.Text = bi.CURRENT_INSTALLMENT.ToString("n0");
                txtOfferPlafon.Text = bi.OFFER_PLAFON.ToString("n0");
                txtKodyaKab.Text = bi.KODYA_KAB_BUSINESS;
                txtKecamatan.Text = bi.KECAMATAN_BUSINESS;
                txtKelurahan.Text = bi.KELURAHAN_BUSINESS;
                txtAlamat.Text = bi.ADDRESS_BUSINESS;
                txtKodePos.Text = bi.ZIP_CODE_BUSINESS;
                txtProspectType.Text = bi.PROSPECT_TYPE;
                txtDebtorType.Text = bi.DEBTOR_TYPE;
                txtChannel.Text = bi.CHANNELING;
            }
        }

        private void BindUserSO()
        {
            Shuba.Business.User bl = new Shuba.Business.User();
            List<Shuba.Model.UserInfo> list = bl.GetUserSO(Session["UnitID"].ToString());
            ddlAO.DataSource = list;
            ddlAO.DataTextField = "Name";
            ddlAO.DataValueField = "UserCode";
            ddlAO.DataBind();

            if (ddlAO.Items.Count > 0)
            {
                ListItem ListAll = new ListItem();
                ListAll.Value = "PILIH";
                ListAll.Text = "- Pilih dengan benar -";
                ddlAO.Items.Insert(0, ListAll);
            }
        }

        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                Shuba.Business.TopUp bl = new Shuba.Business.TopUp();
                if (bl.UpdateAssigned(Request.QueryString["cif"], Request.QueryString["loan"], ddlAO.SelectedValue, HttpContext.Current.User.Identity.Name) > 0)
                {
                    AddLog("UPDATE", " UPDATE TOPUP ASSIGNED");
                    AlertAndRedirect("Topup sukses diassign", "topup_assignment_list.aspx");
                }
            }
            catch (Exception) { }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("topup_assignment_list.aspx");
        }
    }
}